atspicontext: Implement GetIndexInParent
authorMatthias Clasen <mclasen@redhat.com>
Sat, 10 Oct 2020 00:24:52 +0000 (20:24 -0400)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 12 Oct 2020 15:19:32 +0000 (16:19 +0100)
This is needed for ATs to take our tree seriously.

gtk/a11y/gtkatspicontext.c

index 4ed4f97f182072047f7d075fe5f8ca5341e656a4..4d24f1a9595dc894624acb94652e4d3ec2388a84 100644 (file)
@@ -200,6 +200,30 @@ handle_accessible_method (GDBusConnection       *connection,
 
       g_dbus_method_invocation_return_value (invocation, g_variant_new ("(a(so))", &builder));
     }
+  else if (g_strcmp0 (method_name, "GetIndexInParent") == 0)
+    {
+      GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
+      GtkWidget *widget = GTK_WIDGET (accessible);
+      GtkWidget *parent = gtk_widget_get_parent (widget);
+      GtkWidget *child;
+      int idx;
+
+      idx = 0;
+      for (child = gtk_widget_get_first_child (parent);
+           child;
+           child = gtk_widget_get_next_sibling (child))
+        {
+          if (!gtk_widget_get_visible (child))
+            continue;
+
+          if (child == widget)
+            break;
+
+          idx++;
+        }
+
+      g_dbus_method_invocation_return_value (invocation, g_variant_new ("(i)", idx));
+    }
 }
 
 static GVariant *